package com.nbsaas.boot.promote.rest.convert;

import com.nbsaas.boot.promote.data.entity.Coupon;
import com.nbsaas.boot.promote.api.domain.simple.CouponSimple;

import com.nbsaas.boot.rest.api.Converter;
import java.util.HashMap;
import java.util.Map;

/**
* 优惠券-列表对象转换器
*/

public class CouponSimpleConvert implements Converter<CouponSimple, Coupon> {




@Override
public CouponSimple convert(Coupon source) {
    CouponSimple result = new CouponSimple();

                result.setUseEndTime(source.getUseEndTime());
                result.setOrderAmount(source.getOrderAmount());

               try {
                   if(source.getShop()!=null){
                       result.setShop(source.getShop().getId());
                   }
                } catch (Exception ignored) { }

                result.setExpireType(source.getExpireType());
                result.setName(source.getName());
                result.setDiscountAmount(source.getDiscountAmount());
                result.setUseBeginTime(source.getUseBeginTime());
                if(source.getState()!=null){
                   Map<Integer,String> StateMap=new HashMap<>();
                       StateMap.put(1,"未使用");
                       StateMap.put(2,"已使用");
                       StateMap.put(3,"已过期");
                   String label=  StateMap.get(source.getState());
                   result.setStateName(label);
                }
                result.setState(source.getState());
                result.setId(source.getId());

                try {
                    if(source.getCustomer()!=null){
                        result.setCustomerName(source.getCustomer().getName());
                    }
                } catch (Exception ignored) { }


               try {
                   if(source.getCustomer()!=null){
                       result.setCustomer(source.getCustomer().getId());
                   }
                } catch (Exception ignored) { }



    return result;
}

}